package com.atguigu.dao.impl;

import com.atguigu.dao.OrderDao;
import com.atguigu.pojo.Book;
import com.atguigu.pojo.Order;

import java.util.List;

//这里头就是写sql,然后在dao对象中执行
public class OrderDaoImpl extends BaseDao implements OrderDao {

    @Override
    public Integer saveOrder(Order order) {
        System.out.println("OrderDaoImpl程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_order(`order_id`,`create_time`," +
                "`price`,`status`," +
                "`user_id`) values(?,?,?,?,?);";
        return update(sql,order.getOrderId(),order.getCreateTime(),order.getPrice(),order.getStatus(),order.getUserId());
    }

    @Override
    public List<Order> queryOrders() {
        String sql ="select `order_id` orderId,`create_time` createTime,`price`,`status`,`user_id` userId from t_order";
        return queryForList(Order.class,sql);
    }

    @Override
    public Integer changeOrderStatus(String orderId, Integer status) {
        String sql="update t_order set `status`=? where order_id=?";
        return update(sql,status,orderId);
    }

    @Override
    public List<Order> queryOrderByUserId(Integer userId) {
        String sql ="select `order_id` orderId,`create_time` createTime,`price`,`status`,`user_id` userId from t_order where user_id = ?";
        return queryForList(Order.class,sql,userId);
    }
}
